package com.businesscard.system.common;

import org.springframework.boot.web.server.MimeMappings;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.annotation.Configuration;

/**
 * MIME类型配置
 */
@Configuration
public class MimeTypeConfig implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {

    @Override
    public void customize(ConfigurableServletWebServerFactory factory) {
        MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);

        // 确保CSS文件的MIME类型正确
        mappings.add("css", "text/css");

        // 确保JavaScript文件的MIME类型正确
        mappings.add("js", "application/javascript");

        // 确保JSON文件的MIME类型正确
        mappings.add("json", "application/json");

        // 确保HTML文件的MIME类型正确
        mappings.add("html", "text/html");

        // 确保字体文件的MIME类型正确
        mappings.add("ttf", "font/ttf");
        mappings.add("woff", "font/woff");
        mappings.add("woff2", "font/woff2");
        mappings.add("eot", "application/vnd.ms-fontobject");

        // 确保图片文件的MIME类型正确
        mappings.add("png", "image/png");
        mappings.add("jpg", "image/jpeg");
        mappings.add("jpeg", "image/jpeg");
        mappings.add("gif", "image/gif");
        mappings.add("svg", "image/svg+xml");
        mappings.add("ico", "image/x-icon");

        factory.setMimeMappings(mappings);
    }
}
